<?php
/*
 * @Author: lokei
 * @Date: 2023-03-19 12:10:18
 * @LastEditors: lokei
 * @LastEditTime: 2023-03-23 15:23:16
 * @Description: 
 */
namespace App\Http\Controllers\Store\Douyin;

use App\Common\Douyin\Common;
use App\Common\Tools\ResultTool;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class StoreController extends Controller {
    public function list(Request $request) {
        $params = [
            'account_id' => $request->input('account_id'),
            'page' => 1,
            'size' => 20
        ];
        // 这里的参数需要使用raw的方式传参（！！！！这里需要注意）
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, "https://open.douyin.com/goodlife/v1/shop/poi/query/");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params)); // 必须为字符串
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'access-token: ' . Common::getAccessToken())); // 必须声明请求头
        // 如果没有错误的话返回的就是小程序码的文件流
        $result_str = curl_exec($ch);
        $result = json_decode($result_str, true);
        $res = ResultTool::success();
        $res['data']['items'] = $result['data']['pois'];
        return $res;
    }
}